package com.cheng.algorithm.recursion;

/**
 * @User Administrator
 * @Classname RecursionTest
 * @Project Data-structure-and-algorithm
 * @Description 递归调用机制
 * @Author wpcheng
 * @Create 2021-07-23-9:40
 * @Version 1.0
 */
public class RecursionTest {
    public static void main(String[] args) {
        test1(5);
        System.out.println(factorial(3));

    }
    //打印
    public static  void test1(int n){
        if (n > 2){
            test1(n -1);
        }
        System.out.println("n="+n);
    }
    //阶乘
    public static int factorial(int n){
        if (n == 1){
            return 1;
        }else {
            return factorial(n -1) * n;  //n=3: factorial(2)*3 = factorial(1)*2*3 = 1*2*3
        }
    }
}
